﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WCSY.MODEL;
using WCSY.BLL;

namespace ContractSystem.WebUI
{
    public partial class Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if(!IsPostBack){
                if (Session["userName"] == null)
                {
                    ClientScript.RegisterStartupScript(this.GetType(), "", "<script>chkLogin();</script>");
                }
                else
                {
                    lblUser.Text = Session["userName"].ToString();
                    string userId = Session["userId"].ToString();
                    string roleId = tool.getRoleIdByUserId(userId);
                    pareentNode(roleId);
                }
                
            }
        }

        public void pareentNode(string roleId)
        {
            string sql = "select a.rightsid,a.parentid,a.rightsname,a.rightstype,a.rightsurl,a.remarks" +
            " from  mg_rights as a,mg_rrrelation as b " +
            "  where a.rightsid=b.rightsid  and a.rightstype=1 " +
            "  and parentid='0' and b.roleid='" + roleId + "'";
            List<Mg_right> rights = Mg_rightManager.GetMg_rightsBySql(sql) as List<Mg_right>;
            //Rights.GetChildRight(tnode.Value);
            //TreeView1.Nodes.Clear();

            foreach (Mg_right t in rights)
            {
                //TreeNode root = new TreeNode();
                string rootValue = t.Rightsname;
                int rootId = t.Rightsid;
                //root.Text = rootValue;
                //root.Value = rootId.ToString();
                ChannelMenuItems.Controls.Add(new LiteralControl("<li>"));//添加<li>标签
                ChannelMenuItems.Controls.Add(new LiteralControl("<a id=\"A"+rootId+"\" href=\"Components/SystemMenus/MenuLeft.aspx?parentid="+rootId+"&parentname="+rootValue+"&roleid="+roleId+"\" target=\"left\">"));
                ChannelMenuItems.Controls.Add(new LiteralControl("<span id=\"SpanChannelMenu_Menuxx"+t.Rightsid+"\">"+rootValue+""));

                ChannelMenuItems.Controls.Add(new LiteralControl("</span>"));//嵌套<span>标签里面的内容
                ChannelMenuItems.Controls.Add(new LiteralControl("</a>"));//嵌套<a>标签里面的内容
                ChannelMenuItems.Controls.Add(new LiteralControl("</li>"));

                //TreeView1.Nodes.Add(root);
                //root.ImageUrl = "~/image/base1.gif";
                //childNodes(root);
            }
        }

        //更改用户登录状态
        protected void modifyUserStatus_Click(object sender, EventArgs e)
        {
            if (Session["userId"] != null)
            {
                Mg_userManager userM = new Mg_userManager();
                string userid = Session["userId"].ToString();
                userM.ModifyMg_userStatus(userid, "0");
            }
        }

       
    }
}
